package com.sgb.kjwl.view.ui.adapter.enterprise;

import android.content.Context;
import android.graphics.Color;
import android.util.TypedValue;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.enterprise.IntellpropEntity;
import com.sgb.kjwl.utils.ActivityJump;
import com.sgb.kjwl.utils.DialogFunction;
import com.sgb.kjwl.utils.DialogHelper;
import com.sgb.kjwl.utils.DisplayUtil;
import com.sgb.kjwl.utils.TextSizeUtils;
import com.swgk.core.event.EventConstant;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

public class IntellpropAdapter extends BaseRecycleAdapter<IntellpropEntity> {
    Context context;
    TextView tv_tag;

    public IntellpropAdapter(Context context, List<IntellpropEntity> datas) {
        super(context, R.layout.item_intellprop, datas);
        this.context = context;
    }

    @Override
    public void convert(ItemViewHolder holder, IntellpropEntity intellpropEntity) {
        holder.setBinding(BR.viewModel, intellpropEntity);

//        ItemIntellpropBinding itemIntellpropBinding = (ItemIntellpropBinding) holder.getmBinding();
//        if (intellpropEntity.getPrice() == -1) {
//            holder.setText(R.id.price_view, "议价");
//        } else {
//            holder.setText(R.id.price_view, TextViewBindingAdapter.setMoneyForRMB(PointUtils.price(intellpropEntity.getPrice())));
//        }
        tv_tag = holder.getItem().findViewById(R.id.tv_item_intel_prop_publish);
        switch (intellpropEntity.getPublishType()) {
            case 0://个人
                tv_tag.setText("个人");
                tv_tag.setBackgroundResource(R.drawable.shape_radius_1_solid_bule);
                break;
            case 1://企业
                tv_tag.setText("企业");
                tv_tag.setBackgroundResource(R.drawable.shape_radius_1_solid_bule);
                break;
            case 2://团队
                tv_tag.setText("团队");
                tv_tag.setBackgroundResource(R.drawable.ractangle_radius_1_solid_yellow);
                break;
            default:
                tv_tag.setVisibility(View.GONE);
                break;
        }
        if (intellpropEntity.getLabel() != null && intellpropEntity.getLabel().contains("1")) {
            holder.setVisible(R.id.tv_item_intel_prop_hot, true);
        } else {
            holder.setVisible(R.id.tv_item_intel_prop_hot, false);
        }
        if (intellpropEntity.getLabel() != null && intellpropEntity.getLabel().contains("2")) {
            holder.setVisible(R.id.tv_item_intel_prop_urgent_sale, true);
        } else {
            holder.setVisible(R.id.tv_item_intel_prop_urgent_sale, false);
        }

        holder.getItem().findViewById(R.id.btn_chat).setOnClickListener(view -> {
            if (DialogHelper.checkLogin()) {
                DialogHelper.showDialog(context, "确认呼叫", intellpropEntity.getContacts() + ":" + intellpropEntity.getContactNumber(), "确定", new DialogFunction() {
                    @Override
                    public void normalRoundDialog() {
                        ActivityJump.jumpToPhone(context, intellpropEntity.getContactNumber());
                    }
                });
            } else {
                DialogHelper.showLoginDialogNew(context, EventConstant.EVENT_INTELL_PROP_FRG_JUMP, "温馨提示", "登录后可拨打电话,去登录", "登录");
            }

        });
        ImageView roundImageView = holder.getItem().findViewById(R.id.logo_view);
        TextView logoViewText = holder.getItem().findViewById(R.id.logo_view_text);

        if (intellpropEntity.getImg() != null && !intellpropEntity.getImg().equals("")) {
            logoViewText.setVisibility(View.GONE);
            roundImageView.setVisibility(View.VISIBLE);
            Glide.with(context).load(intellpropEntity.getImg()).apply(RequestOptions.bitmapTransform(new RoundedCorners(2))).into(roundImageView);
        } else {
//            roundImageView.setImageResource(R.mipmap.morentu_change);
            logoViewText.setVisibility(View.VISIBLE);
            roundImageView.setVisibility(View.INVISIBLE);
            if (intellpropEntity.getName().length() == 1){
                logoViewText.setTextSize(TypedValue.COMPLEX_UNIT_SP,22);
            }else {
                logoViewText.setTextSize(TypedValue.COMPLEX_UNIT_SP,(Math.max((20 - 2 * (intellpropEntity.getName().length() / 2)), 10)));
            }
            logoViewText.setTextColor(Color.parseColor("#B79255"));
            logoViewText.setText(TextSizeUtils.singleTextLine(DisplayUtil.dip2px(context,65),logoViewText.getTextSize(),intellpropEntity.getName()));
        }

    }


}
